﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Script.Serialization;

namespace PagingControl.JSon
{
    /// <summary>
    /// Summary description for jsonData
    /// </summary>
    public class jsonData : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Clear();
            context.Response.ContentType = "text/plain";

            var serializer = new JavaScriptSerializer();

            var persons = new List<Person>();
            for(int i =0;i<10;i++)
            {
                var address = new Address {Country = "US",State = "CA", City = "NewYork"};
                var person = new Person {Name = "Jack", Gender = "Male", DOB = DateTime.Now.AddYears(-30), Address = address};
                persons.Add(person);
            }
            var jsonString = serializer.Serialize(persons);
            context.Response.Write(jsonString);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}